-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add query cancel sync for presto forward #41
base: main
Are you sure you want to change the base?
Conversation
queryStateFailed = "FAILED" | ||
) | ||
|
||
type QueryCache struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type QueryCache struct { | |
type QueryCacheEntry struct { |
to be more precise
runningTasks sync.WaitGroup | ||
failedToForward atomic.Uint32 | ||
forwarded atomic.Uint32 | ||
runningQueriesCacheMap = make(map[string]*[]QueryCache) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment for this, what is the kay and value for.
@@ -171,6 +187,16 @@ func Run(_ *cobra.Command, _ []string) { | |||
Msgf("finished forwarding queries") | |||
} | |||
|
|||
func checkAndCancelQuery(ctx context.Context, queryState *presto.QueryStateInfo) { | |||
if queryCaches, ok := runningQueriesCacheMap[queryState.QueryId]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if queryCaches, ok := runningQueriesCacheMap[queryState.QueryId]; ok { | |
if queryCacheEntries, ok := runningQueriesCacheMap[queryState.QueryId]; ok { |
@@ -226,9 +252,10 @@ func forwardQuery(ctx context.Context, queryState *presto.QueryStateInfo, client | |||
} | |||
successful, failed := atomic.Uint32{}, atomic.Uint32{} | |||
forwardedQueries := sync.WaitGroup{} | |||
cachedQueries := []QueryCache{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cachedQueries := []QueryCache{} | |
cachedQueries := make([]QueryCache, len(clients)-1) |
Pre-allocate the elements to prevent racing conditions.
See my comment below.
) | ||
|
||
type QueryCache struct { | ||
QueryId string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like we do not need the QueryId field here right?
@@ -246,6 +273,10 @@ func forwardQuery(ctx context.Context, queryState *presto.QueryStateInfo, client | |||
failed.Add(1) | |||
return | |||
} | |||
//build cache for running query | |||
if clientResult.NextUri != nil { | |||
*cachedQueries = append(*cachedQueries, QueryCache{QueryId: clientResult.Id, NextUri: *clientResult.NextUri, Client: client}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you write to cachedQueries concurrently, which could lead to issues.
In the comment above I requested to pre-allocate the elements. so here you can just update element using index i-1
, without needing to update the cachedQueries value
Background:
Presto forward is a feature to monitor the workload in source Presto cluster and then clone the workload to target clusters.
It's well working. There is one requirement which to syncronize the query cancel to target clusters. That means when the workload is canceled in source cluster, the target cluster should cancel the workload as well.
Solution: